﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Il2CppAnti
{
    class Program
    {
        /// <summary>
        /// 使用方法
        /// </summary>
        static void Useage()
        {
            Console.WriteLine("Il2CppAnti \"C:\\Program Files\\Unity\\Hub\\Editor\\2019.4.22f1c1\\Editor\\Data\\il2cpp\"");
        }

        static void Main(string[] args)
        {
            int len = args.Length;
            var paths = new Paths();
            var types = new List<Type>() {
                typeof(BlockIl2cppMetadata),
                typeof(BlockMetadataCache),
                typeof(BlockIl2cppAssemblyConverter),
                typeof(BlockIl2cppMoveSectionHeader),
                typeof(BlockIl2cppMagicVersion),
            };

            if (len < 1)
            {
                Useage();
                return;
            }

            var p = args[0];
            if (!Directory.Exists(p))
            {
                Console.WriteLine($"{p} 路径不存在");
                return;
            }

            paths.ROOT = p;   
            if (!paths.Check())
            {
                Console.WriteLine("路径检查不通过");
                return;
            }

            foreach (var t in types)
            {
                var ins = (IBlock)Activator.CreateInstance(t, paths);
                ins.Decompile();
                ins.Replace();
                ins.Compile();
            }
        }
    }
}
